<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>Best of Vim Tips 中文版 | 净土</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="A blog of howiefh.">
<meta property="og:type" content="article">
<meta property="og:title" content="Best of Vim Tips 中文版">
<meta property="og:url" content="http://howiefh.github.io/2014/01/26/best-vim-tips/index.html">
<meta property="og:site_name" content="净土">
<meta property="og:description" content="A blog of howiefh.">
<meta property="og:updated_time" content="2014-12-24T07:43:41.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Best of Vim Tips 中文版">
<meta name="twitter:description" content="A blog of howiefh.">
  
    <link rel="alternative" href="/atom.xml" title="净土" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.ico">
  
  <link href="http://fonts.useso.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css" type="text/css">
  
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-40492061-1', 'auto');
ga('send', 'pageview');

</script>


  
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?56d2899c5e919fbf4a7b00de5d1c31dd";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>


</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">净土</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">乐不在外而在心，心以为乐，则是境皆乐；心以为苦，则无境不苦。</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-github-link" class="nav-icon" href="https://github.com/howiefh" title="Github" target="_blank"></a>
        
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed" target="_blank"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://howiefh.github.io"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-best-vim-tips" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    
<a href="/2014/01/26/best-vim-tips/" class="article-date">
  <time datetime="2014-01-26T09:48:52.000Z" itemprop="datePublished">2014-01-26</time>
</a>


    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Vim/">Vim</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Best of Vim Tips 中文版
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
		
		<div id="toc" class="toc-article">
			<h2 class="toc-title"><span>Contents</span></h2>
		
			
		
		</div>
		
        <p>这篇文章出自：<a href="https://groups.google.com/d/msg/vim-cn/XCVyjj7svs4/AVGVRQa6L_cJ" target="_blank" rel="external">https://groups.google.com/d/msg/vim-cn/XCVyjj7svs4/AVGVRQa6L_cJ</a></p>
<a id="more"></a>    
<pre style="background-color:white;color:black;">
这是篇每个 Vim 用户都应该阅读的文章，原文在这里 
http://www.rayninfo.co.uk/vimtips.html
这篇文章很早被翻译过，好像是一个清华的哥们翻译的。我再原来的基础上又整理
和新增了些内容--这是两年前做的，后来没有再更新。有兴趣的人可以继续更新。

__BEGIN__
------------------------------------------------------------------------------
# searching 查找
/joe/e                      : cursor set to End of match
                              把光标定位在匹配单词最后一个字母处
/joe/e+1                    : cursor set to End of match plus 1
                              把光标定位在匹配单词最后一个字母的下一个字母处
/joe/s-2                    : cursor set to Start of match minus 2
                              把光标定位在匹配单词第一个字母往前数两个字母的位置
/^joe.*fred.*bill/          : normal
                              标准的正则表达式
/^[A-J]\+/                  : search for lines beginning with one or more A-J
                              查找以一个或多个 A-J 中的字母开头的行
/begin\_.*end               : search over possible multiple lines
                              查找在 begin 和 end 两个单词之间尽可能多的行
/fred\_s*joe/i              : any whitespace including newline
                              查找在 fred 和 joe 两个单词之间任意多的空格，包括新行
/fred\|joe                  : Search for FRED OR JOE
                              查找 fred 或 joe
/\([^0-9]\|^\)%.*%          : Search for absence of a digit or beginning of line
                              查找
/.*fred\&.*joe              : Search for FRED AND JOE in any ORDER!
                              查找同时包含 FRED 和 JOE 的行，不分前后顺序
/\<fred\>/i              : search for fred but not alfred or frederick
                              查找 fred, 而不是 alfred 或者 frederick，也就是全字匹配
/\<\d\d\d\d\>            : Search for exactly 4 digit numbers
                              查找4个数字的全字匹配
/\D\d\d\d\d\D               : Search for exactly 4 digit numbers
                              查找4个数字的全字匹配
/\<\d\{4}\>              : same thing
                              同上

# finding empty lines 查找空行
/^\n\{3}                    : find 3 empty lines
                              查找 3 行空行
# Specify what you are NOT searching for (vowels)
# 指定不要查找什么
/\c\v([^aeiou]&\a){4}       : search for 4 consecutive consanants

# using rexexp memory in a search
# 在查找中使用正则表达式存储
/\(fred\).*\(joe\).*\2.*\1

# Repeating the Regexp (rather than what the Regexp finds)
# 重复正则表达式
/^\([^,]*,\)\{8}

# visual searching
# 可视模式下的查找
:vmap // y/<c-r>"<cr>       : search for visually highlighted text
                                     查找被高亮显示的文本
:vmap <silent> //    y/<c-r>=escape(@", '\\/.*$^~[]')<cr><cr> : with spec chars

# searching over multiple lines \_ means including newline
# 查找多行。\_ 表示包括新行
/<!--\_p\{-}-->                : search for multiple line comments
                                     查找多行注释
/fred\_s*joe/i                    : any whitespace including newline
                                     查找在 fred 和 joe 两个单词之间任意多的空 
格，包括新行
/bugs\(\_.\)*bunny                : bugs followed by bunny anywhere in file
                                     bugs 后任意位置含有 bunny 单词的多个行
:h \_                             : help
                                     帮助

# search for declaration of subroutine/function under cursor
# 查找光标下子程序/函数的声明
:nmap gx yiw/^\(sub\<bar>function\)\s\+<c-r>"<cr>

# multiple file search
# 在多个文件中查找
:bufdo /searchstr
:argdo /searchstr

# How to search for a URL without backslashing
# 如何不使用反斜线查找 URL
?http://www.vim.org/        : search BACKWARDS!!! clever huh!
----------------------------------------
# substitution
# 替换
:%s/fred/joe/igc            : general substitute command
                               普通替换命令
:%s/\r//g                   : Delete DOS returns ^M
                               删除 DOS 回车符 ^M

# Is your Text File jumbled onto one line? use following
# 你的文本文件是否乱七八糟的排成一行？使用如下命令
:%s/\r/\r/g                 : Turn DOS returns ^M into real returns
                               转换 DOS 回车符 ^M 为真正的回车符
:%s=  *$==                  : delete end of line blanks
                               删除行尾空格
:%s= \+$==                  : Same thing
                               同上
:%s#\s*\r\?$##              : Clean both trailing spaces AND DOS returns
                               删除行尾空格和 DOS 回车符
:%s#\s*\r*$##               : same thing
                               删除行尾空格和 DOS 回车符

# deleting empty lines
# 删除空行
:%s/^\n\{3}//               : delete blocks of 3 empty lines
                               删除三行空行
:%s/^\n\+/\r/               : compressing empty lines
                              压缩多行空行为一行

# IF YOU ONLY WANT TO KNOW ONE THING
# 如果你只想明白一件事情
:'a,'bg/fred/s/dick/joe/igc : VERY USEFUL
                               非常有用

# duplicating columns
# 复制列
:%s= [^ ]\+$=&&=            : duplicate end column
                               复制最后一列
:%s= \f\+$=&&=              : same thing
                               同上
:%s= \S\+$=&&               : usually the same
                               同上
# memory
# 记忆，或叫引用
:s/\(.*\):\(.*\)/\2 : \1/   : reverse fields separated by :
                               反转以 : 分隔的字段
:%s/^\(.*\)\n\1/\1$/        : delete duplicate lines
                               删除重复的行

# non-greedy matching \{-}
# 非贪婪匹配 \{-}
:%s/^.\{-}pdf/new.pdf/      : delete to 1st pdf only
                               只删除到第一个 pdf

# use of optional atom \?
:%s#\<[zy]\?tbl_[a-z_]\+\>#\L&#gc : lowercase with optional leading characters
                                        不懂

# over possibly many lines
# 匹配尽可能多的行
:%s/<!--\_.\{-}-->//        : delete possibly multi-line comments
                                  删除尽可能多的注释
:help /\{-}                 : help non-greedy
                               非贪婪匹配的帮助

# substitute using a register
# 使用寄存器替换
:s/fred/<c-r>a/g         : sub "fred" with contents of register "a"
                               用"a"寄存器里的内容替换"fred"
:s/fred/\=@a/g              : better alternative as register not displayed
                               更好的方法，不用显示寄存器内容

# multiple commands on one line
# 写在一行里的复杂命令
:%s/\f\+\.gif\>/\r&\r/g | v/\.gif$/d | %s/gif/jpg/

# ORing
:%s/suck\|buck/loopy/gc     : ORing (must break pipe)
                               不懂
# Calling a VIM function
# 调用 Vim 函数
:s/__date__/\=strftime("%c")/ : insert datestring
                                插入日期

# Working with Columns sub any str1 in col3
# 处理列，替换所有在第三列中的 str1
:%s:\(\(\w\+\s\+\)\{2}\)str1:\1str2:

# Swapping first & last column (4 columns)
# 交换第一列和最后一列 (共4列)
:%s:\(\w\+\)\(.*\s\+\)\(\w\+\)$:\3\2\1:

# filter all form elements into paste register
# 把所有的form元素（就是html里面的form啦）放到register里
:redir @*|sil exec 'g#<\(input\|select\|textarea\| \="form\)\">#p'|redir END
:nmap ,z :redir @*<bar>sil exec 
'g@<\(input\<bar>select\<bar>textarea\<bar>/\=form\)\>@p'<bar>redir END<cr>

# increment numbers by 6 on certain lines only
# 不懂
:g/loc\|function/s/\d/\=submatch(0)+6/

# better
# 更好的方法
:%s#txtdev\zs\d#\=submatch(0)+1#g
:h /\zs

# increment only numbers gg\d\d  by 6 (another way)
# 不懂
:%s/\(gg\)\@<=\d\+ \="submatch(0)+6/" :h="" zero-width="" #="" find="" replacement="" text,="" put="" in="" memory,="" then="" use="" \zs="" to="" simplify="" substitute="" 查找需替换的文本，保存，然后使用="" 命令简单替换="" :%s="" "\([^.]\+\).*\zsxx="" \1="" pull="" word="" under="" cursor="" into="" lhs="" of="" a="" 不懂="" :nmap="" <leader="">z :%s#\<<c-r>=expand("<cword>")<cr>\>#

# Pull Visually Highlighted text into LHS of a substitute
# 不懂
:vmap <leader>z :<c-u>%s/\<<c-r>*\>/

----------------------------------------

# all following performing similar task, substitute within substitution
# Multiple single character substitution in a portion of line only

:%s,\(all/.*\)\@<= ,_,g="" :="" replace="" all="" with="" _="" after="" "all="" "="" #="" same="" thing="" :s#all="" \zs.*#\="substitute(submatch(0)," '="" ',="" '_',="" 'g')#="" substitute="" by="" splitting="" line,="" then="" re-joining="" #&^m#|s#="" #_#g|-j!="" inside="" :%s="" .*="" \="cp " .submatch(0).'="" '.substitute(submatch(0),'="" ','_','g')="" ----------------------------------------="" global="" command="" display="" (see="" tip="" 227)="" 全局命令显示（参见="" :g="" fred.*joe.*dick="" lines="" fred,joe="" &="" dick="" 显示所有包含fred,joe="" 和="" 的行="" \<fred\="">/             : display all lines fred but not freddy
                               显示所有全字匹配 fred 的行
:g/<pattern>/z#.5        : display with context
                               显示上下文
:g/<pattern>/z#.5|echo "=========="  : display beautifully
                                           显示得很漂亮
:g/^\s*$/d                  : delete all blank lines
                               删除所有的空行
:g!/^dd/d                   : delete lines not containing string
                               删除所有行首不是 dd 的行
:v/^dd/d                    : delete lines not containing string
                              同上
:g/fred/,/joe/d             : not line based (very powerfull)
                               并不基于行(非常强大)
:g/{/ ,/}/- s/\n\+/\r/g     : Delete empty lines but only between {...}
                               删除在 {...} 只见的空行
:v/./.,/./-1join            : compress empty lines
                               压缩空行
:g/^$/,/./-j                : compress empty lines
                               压缩空行
:g/<input\|<form p="" :="" oring="" 不懂="" :g="" ^="" pu="" _="" double="" space="" file="" (pu="put)" 把文件中空行增加一倍="" m0="" reverse="" (m="move)" 翻转文件="" fred="" t$="" copy="" lines="" matching="" to="" eof="" 把匹配="" 的行拷贝到文件最后="" stage="" t'a="" marker="" a="" 的行做标记a="" :%norm="" jdd="" delete="" every="" other="" line="" 隔一行删除一行="" #="" incrementing="" numbers="" (type="" <c-a=""> as 5 characters)
:.,$g/^\d/exe "norm! \<c-a>": increment numbers
                                  增加每行行首的数字
:'a,'bg/\d\+/norm! ^A          : increment numbers
                                  增加标记 a 到标记 b 只见每行行首的数字

# storing glob results (note must use APPEND)
# 保存全局命令的结果 (注意必须使用添加模式)
:g/fred/y A                 : append all lines fred to register a
                               添加所有为fred所匹配的行到register a
:'a,'b g/^Error/ . w >> errors.txt

# duplicate every line in a file wrap a print '' around each duplicate
# 复制每一行，然后在复制出来的每一行两侧加上一个 print '复制出来的内容'
:g/./yank|put|-1s/'/"/g|s/.*/Print '&'/

# replace string with contents of a file, -d deletes the "mark"
# 用文件中的内容替换字符串，-d 表示删除“标记”
:g/^MARK$/r tmp.ex | -d

----------------------------------------

# Global combined with substitute (power editing)
# 全局命令和替换命令联姻 (强大的编辑能力)
:'a,'bg/fred/s/joe/susan/gic :  can use memory to extend matching
                                 可以使用反向引用来匹配
:g/fred/,/joe/s/fred/joe/gic :  non-line based (ultra)

----------------------------------------

# Find fred before beginning search for joe
# 先找fred，然后找joe
:/fred/;/joe/-2,/sid/+3s/sally/alley/gIC

----------------------------------------

# Absolutely essential
# 基础

----------------------------------------
* # g* g#           : find word under cursor (<cword>) (forwards/backwards)
                       寻找光标处的狭义单词(<cword>) (前向/后向)
%                   : match brackets {}[]()
                       括号配对寻找 {}[]()
.                   : repeat last modification

matchit.vim         : % now matches tags tr、td、script <?php etc
                       使得 % 能够配对标记 tr、td、script <?php 等等
<C-N><c-p>          : word completion in insert mode
                             插入模式下的单词自动完成
<c-x><c-l>          : Line complete SUPER USEFUL
                             行自动完成(超级有用)
/<c-r><c-w>         : Pull <cword> onto search/command line
                             把狭义单词 <cword> 写到 搜索命令行
/<c-r><c-a>         : Pull <cword> onto search/command line
                             把广义单词 <cword> 写到 搜索命令行
:set ignorecase     : you nearly always want this
                       搜索时忽略大小写
:syntax on          : colour syntax in Perl,HTML,PHP etc
                       在 Perl,HTML,PHP 等中进行语法着色
:h regexp<c-d>      : type control-D and get a list all help topics containing
                          按下 control-D 键即可得到包含有 regexp 的帮助主题的列表
                       regexp (plus use TAB to Step thru list)
                       (使用TAB可以实现帮助的自动补齐)
----------------------------------------
# MAKE IT EASY TO UPDATE/RELOAD _vimrc
# 使更新 _vimrc 更容易
:nmap ,s :source $VIM/_vimrc
          # 译释：nmap 是绑定一个在normal模式下的快捷键
:nmap ,v :e $VIM/_vimrc
          # 译释：在normal模式下，先后按下 ,s 两个键执行_vimrc，而 ,v 则是编辑_vimrc

----------------------------------------

#VISUAL MODE (easy to add other HTML Tags)
# visual 模式 (例子是：轻松添加其他的 HTML Tags)
:vmap sb "zdi<b><c-r>z</c-r></b><esc>  : wrap <b></b> around VISUALLY selected Text
                                                在visual模式下选中的文字前后分别 
加上<b>和</b>
:vmap st "zdi<?= <C-R>z ?><esc>  : wrap <?=   ?> around VISUALLY selected Text
                                             在visual模式下选中的文字前后分别加 
上<?= 和 ?>

----------------------------------------

# Exploring
# 文件浏览
:Exp(lore)                      : file explorer note capital Ex
                                   开启目录浏览器，注意首字母E是大写的
:Sex(plore)                     : file explorer in split window
                                   在一个分割的窗口中开启目录浏览器
:ls                             : list of buffers
                                   显示当前buffer的情况
:cd ..                          : move to parent directory
                                   进入父目录
:args                           : list of files
                                   显示目前打开的文件
:lcd %:p:h                      : change to directory of current file
                                   更改到当前文件所在的目录
:autocmd BufEnter * lcd %:p:h   : change to directory of current file 
automatically (put in _vimrc)
                                   自动更改到当前文件所在的目录 (放到 _vimrc)

----------------------------------------

# Buffer Explorer (Top Ten Vim Script)
# 缓冲区(buffer)浏览器 (第三方的一个最流行的脚本)
# needs bufexplorer.vim  http://www.vim.org/script.php?script_id=42
# 需要下载 bufexplorer.vim
\be                             : buffer explorer list of buffers
                                   在缓冲区浏览器中打开缓冲区列表
\bs                             : buffer explorer (split window)
                                   以分割窗口的形式打开缓冲区浏览器

----------------------------------------

# Changing Case
guu                             : lowercase line
                                   行小写
gUU                             : uppercase line
                                   行大写
Vu                              : lowercase line
                                   行小写
VU                              : uppercase line
                                   行大写
g~~                             : flip case line
                                   行翻转
vEU                             : Upper Case Word
                                   字大写(狭义字)
vE~                             : Flip Case Word
                                   字翻转(狭义字)
ggguG                           : lowercase entire file
                                   把整个文章全部小写

# Titlise Visually Selected Text (map for .vimrc)
vmap ,c :s/\<\(.\)\(\k*\)\>/\u\1\L\2/g<cr>
# Uppercase first letter of sentences
# 大写所有句子的第一个字母
:%s/[.!?]\_s\+\a/\U&\E/g

----------------------------------------

gf                              : open file name under cursor (SUPER)
                                   取当前光标处的广义字作为文件名，然后试图打开它！
ga                              : display hex,ascii value of char under cursor
                                   显示光标处字符的ascii,hex,oct,...
ggVGg?                          : rot13 whole file
                                   用rot13编码整个文件
ggg?G                           : rot13 whole file (quicker for large file)
                                   用rot13编码整个文件(对大文件更快一些)
:8 | normal VGg?                : rot13 from line 8
                                   从第8行开始，用rot13编码后面的文本
:normal 10GVGg?                 : rot13 from line 8
                                   从第8行开始，用rot13编码后面的文本

# 【关于rot13——谁让英文是偶数个字母啊】
# ROT13 是一种简单的编码，它把字母分成前后两组，每组13个，编码和解码
# 的算法相同，仅仅交换字母的这两个部分，即：[a..m] --> [n..z] 和 [n..z]
# --> [a..m] 。 ROT13 用简易的手段使得信件不能直接被识别和阅
# 读，也不会被搜索匹配程序用通常的方法直接找到。经常用于 USENET 中发表一
# 些攻击性或令人不快的言论或有简单保密需要的文章。
# 由于 ROT13 是自逆算法，所以，解码和编码是同一个过程。

<c-a>,<c-x>               : increment,decrement number under cursor
                                   增加,减少 光标处的狭义字所表示的数字
                                   win32 users must remap CNTRL-A
                                   Win32的用户可能需要重新定义一下Ctrl-A
<c-r>=5*5                    : insert 25 into text (mini-calculator)
                                   插入25 (一个迷你计算器)

----------------------------------------

# Makes all other tips superfluous
:h 42            : also http://www.google.com/search?q=42
:h holy-grail
:h!

----------------------------------------

# Markers & moving about
# 标记和移动
'.               : jump to last modification line (SUPER)
                    跳到最后修改的那一行 (超级有用)
`.               : jump to exact spot in last modification line
                    不仅跳到最后修改的那一行，还要定位到修改点
g;               : cycle thru recent changes (oldest first) (new in vim6.3)
                    循环跳转修改点(从最老的修改点开始) (vim6.3中新增)
g,               : reverse direction (new in vim6.3)
                    反向循环跳转修改点 (vim6.3中新增)

:changes
:h changelist    : help for above
<c-o>            : retrace your movements in file (starting from most recent)
                       依次沿着你的跳转记录向回跳 (从最近的一次开始)
<c-i>            : retrace your movements in file (reverse direction)
                       依次沿着你的跳转记录向前跳
:ju(mps)         : list of your movements
                    列出你跳转的足迹
:help jump-motions
:history         : list of all your commands
                    列出历史命令记录
:his c           : commandline history
                    命令行命令历史
:his s           : search history
                    搜索命令历史
q/               : Search history Window
                    搜索命令历史的窗口
q:               : commandline history Window
                    命令行命令历史的窗口
:<c-f>        : history Window
                    历史命令记录的窗口
----------------------------------------
# Abbreviations & maps
# # 缩写和键盘映射
:map   <f7>   :'a,'bw! c:/aaa/x
                  # 译释：map是映射一个normal模式下的键
                  # 这里是把F7键映射成把标记a到标记b中间的内容另存为一个文件/aaa/x
                  # 标记(mark)的方法：把光标移动到需要标记的地方，输入m，然后输 
入标记名，例如a
                  # 引用标记的方法：'a ，即：单引号加标记名
:map   <f8>   :r c:/aaa/x
                  # 译释：把F8键映射成在当前位置插入文件/aaa/x的内容
:map   <f11>  :.w! c:/aaa/xr<cr>
                  # 译释：.（点号）表示当前行
                  # 所以F11就是把当前行存为/aaa/xr
                  # 最后的<cr>表示一个回车
:map   <f12>  :r c:/aaa/xr<cr>
:ab php          : list of abbreviations beginning php
                    列出php表示的缩写
                  # 译释：定义一个缩写使用：:iab hm hmisty
                  # 一个有趣的现象是，它列出的会是php和它的前子串开头的缩写
                  # 例如，有这么几个缩写：
                  # h => hmisty1 , hm => hmisty2 , hmi => hmisty3, m => hmisty4
                  # 那么使用 :ab hm会显示这么几个缩写：hm 和 h
                  # 而不是你想象中的 hm 和 hmi

:map ,           : list of maps beginning ,
                    列出以逗号开始的键盘映射

# allow use of F10 for mapping (win32)
# 允许 F10 的映射用法 (win32)
set wak=no       : :h winaltkeys
                    参见 :h winaltkeys

# For use in Maps
# 在键盘映射中常用的表示
<cr>             : carriage Return for maps
                       回车
<esc>            : Escape
                       ESC
<leader>         : normally \
                       转义符号 \
<bar>            : | pipe
                       管道符号
<backspace>      : backspace
                       退格符号

# display RGB colour under the cursor eg #445588
# 显示光标下数值的 RGB 颜色
:nmap <leader>c :hi Normal guibg=#<c-r>=expand("<cword>")<cr><cr>

----------------------------------------

# Using a register as a map (preload registers in .vimrc)
:let @m=":'a,'bs/"
:let @s=":%!sort -u"

----------------------------------------
# List your Registers
# 列出寄存器(Registers)
:reg             : display contents of all registers
                   显示所有寄存器的内容
:reg a           : display content of individual registers
                    显示 a 寄存器的内容
"1p....          : retrieve numeric registers one by one
:let @y='yy@"'   : pre-loading registers (put in .vimrc)

----------------------------------------

# Useful tricks
# 有用的窍门
"ayy@a           : execute "Vim command" in a text file
                    把当前行作为一个Vim命令来执行
yy@"             : same thing using unnamed register
                    同上，不过是用匿名寄存器
u@.              : execute command JUST typed in
                    只执行键入的命令

----------------------------------------

# Get output from other commands (requires external programs)
# 从其他程序获取输出 (需要外部程序)
:r!ls.exe        : reads in output of ls
                    读取ls的输出到当前位置
!!date           : same thing (but replaces/filters current line)
                    读取date的输出 (但是会替换当前行的内容)
                  # 译释：其实你输入了!!后，vim就自动转换到 :.! 等待你继续输入
# Sorting with external sort
# 使用外部程序sort进行排序(sort是Unix标准命令，ls,date也是)
:%!sort -u       : use an external program to filter content
                    使用sort程序排序整个文件（用结果重写文件）
                  # 译释：%表示整个文件的所有行
                  # !sort表示执行外部命令sort
                  # -u是sort的参数，man sort看看，这个参数的意义是合并相同的行
                  # u就是unique,如果两行内容相同，则结果中只保留一行的说
:'a,'b!sort -u   : use an external program to filter content
                    对mark a 到mark b中间的内容进行排序
!1} sort -u      : sorts paragraph (note normal mode!!)
                    排序当前段落 (只能在normal模式下使用!!)
                  # 译释：!表示使用filter，1}表示filter的对象是从当前行开始向后 
数一段
                  # 段落指到空行处结束，不包括空行
                  # 其实你一旦输入 !1}，vim就自动计算当前段落应该到那一行(eg.+ 
5)，然后生成
                  # :.,.+5! 等待之后输入sort -u，回车，完成操作
                  # .表示当前行，.+5当然就是当前行向后数5行

----------------------------------------

# Multiple Files Management (Essential)
# 多文档操作 (基础)
:bn              : goto next buffer
                    跳转到下一个buffer
:bp              : goto previous buffer
                    跳转到上一个buffer
:wn              : save file and move to next (super)
                    存盘当前文件并跳转到下一个
:wp              : save file and move to previous
                    存盘当前文件并跳转到上一个
:bd              : remove file from buffer list (super)
                    把这个文件从buffer列表中做掉
:bun             : Buffer unload (remove window but not from list)
                    卸掉buffer (关闭这个buffer的窗口但是不把它从列表中做掉)
:badd file.c     : file from buffer list
                    把文件file.c添加到buffer列表
:b 3             : go to buffer 3
                    跳到第3个buffer
:b main          : go to buffer with main in name eg main.c (ultra)
                    跳到一个名字中包含main的buffer,例如main.c
:sav php.html    : Save current file as php.html and "move" to php.html
                    把当前文件存为php.html并打开php.html
:sav! %<.bak :="" save="" current="" file="" to="" alternative="" extension="" 换一个后缀保存="" :sav!="" %:r.cfm="" :e!="" return="" unmodified="" 返回到修改之前的文件(修改之后没有存盘)="" :w="" c:="" aaa="" %="" elsewhere="" 把文件存到一个地儿="" :e="" #="" edit="" 编辑标记为#的buffer(这个buffer必须含有一个可编辑的文件)="" 用ls命令就能看到哪一个buffer有#="" %a表示当前正在编辑的buffer="" u="" 表示不能编辑或者已经被做掉的buffer="" :rew="" beginning="" of="" editted="" files="" list="" (:args)="" 回到第一个可编辑的文件="" :brew="" buffer="" rewind="" 回到第一个buffer="" :sp="" fred.txt="" open into="" a="" split="" 在一个水平分割的窗口中打开文件fred.txt="" 译注：vs="" fred.txt可="" 以实现垂直分割="" :sball,:sb="" all="" buffers="" (super)="" 把当前所有含有可编辑文件的buffer显示到一个分割窗口中="" :scrollbind="" in="" each="" window="" :map="" <f5=""> :ls<cr>:e # : Pressing F5 lists all buffer, just type number
                                 在normal模式下按F5键，则会显示所有含有一个
                                 可编辑文件的buffer，然后提示你输入buffer的序号，
                                 输入后回车，则编辑这个buffer
:set hidden      : Allows to change buffer w/o saving current buffer
                    允许不保存buffer而切换buffer (w/o=without)
----------------------------------------
# Quick jumping between splits
# 在分割窗口中快速切换
:map <c-j> <c-w>j<c-w>_
# 这是一个键盘绑定，把Ctrl-J定义成切换到下一个窗口并最大化
:map <c-k> <c-w>k<c-w>_
# 这是一个键盘绑定，把Ctrl-K定义成切换到上一个窗口并最大化

----------------------------------------
# Recording (BEST TIP of ALL)
# 命令录制 (最佳技巧)
qq  # record to q
       录制到q
your complex series of commands  # 输入一系列复杂的指令
q   # end recording
       再次按q停止录制
@q  # to execute
       执行q中存储的指令
@@  # to Repeat
       重复执行
5@@ # to Repeat 5 times
       重复执行5遍

# editing a register/recording
# 编辑寄存器/录制
"qp            :display contents of register q (normal mode)
                 显示寄存器 q 的内容 (普通模式)
<ctrl-r>q   :display contents of register q (insert mode)
                显示寄存器 q 的内容 (插入模式)

# you can now see recording contents, edit as required
# 你现在可以看到记录内容，随便编辑
"qdd           :put changed contacts back into q
@q             :execute recording/register q
                 执行记录/寄存器 q

# Operating a Recording on a Visual BLOCK
# 在可视块中运行记录
1) define recording/register
1) 定义记录/寄存器
qq:s/ to/ from/g^Mq
2) Define Visual BLOCK
2) 定义可视块
V}
3) hit : and the following appears
3) 键入 : 将显示下面信息
:'<,'>
4)Complete as follows
4) 完成如下操作
:'<,'>norm @q
----------------------------------------
# Visual is the newest and usually the BEST editting mode
# 可视模式是最新也通常是最好的编辑模式
# Visual basics
# 可视模式基础
v              : enter visual mode
                  进入可视模式
V              : visual mode whole line
                  整行的可视模式
<c-v>       : enter VISUAL BLOCK mode
                  进入可视块模式
gv             : reselect last visual area
                  重新选取最新的可视区域
o              : navigate visual area
                  浏览可视区域
"*y            : yank visual area into paste buffer
                  复制可视区域到剪贴板
V%             : visualise what you match
                  ???
V}J            : Join Visual block (great)
                  连接可视块

----------------------------------------

# Delete first 2 characters of 10 successive lines
# 删除连续10行中每行的头2个字符
0<c-v>10j2ld

----------------------------------------

# how to copy a set of columns using VISUAL BLOCK
# 如何用可视块拷贝几列
# visual block (AKA columnwise selection) (NOT BY ordinary v command)
# 可视块(并非通常的 v 命令)
<c-v> then select "column(s)" with motion commands (win32 <c-q>)
<c-v>，然后通过移动命令选择列 (win32 <c-q>)
then c,d,y,r etc
然后执行 c,d,y,r 等命令

----------------------------------------
# _vimrc essentials
# _vimrc基础
:set incsearch : jumps to search word as you type (annoying but excellent)
                  实时匹配你输入的内容
:set wildignore=*.o,*.obj,*.bak,*.exe : tab complete now ignores these
                                         tab键的自动完成现在会忽略这些
:set shiftwidth=3                     : for shift/tabbing
                                         自动缩进设为4个字符
                                       # 译注：一个tab位通常是8个字符
                                       # 所以，我们还要设定 :set tabstop=4，这 
样，所有的缩进都是4字符了
:set vb t_vb=".                       : set silent (no beep)
                                         沉默方式(不要叫beep！)
:set browsedir=buffer                 : Maki GUI File Open use current directory
                                         设置 GUI 版本文件打开时，使用当前路径
----------------------------------------
# launching Win IE
# 加载 IE 浏览器
:nmap ,f :update<cr>:silent !start c:\progra~1\intern~1\iexplore.exe file://%:p<cr>
:nmap ,i :update<cr>: !start c:\progra~1\intern~1\iexplore.exe <cword><cr>
# 译释：nmap是做一个normal模式下的键盘绑定
# 这里绑定了一个逗号命令 ,f
# :update是写这个文件，与:w不同，它只有当文件被修改了的时候才写
# :silent别让弹出窗口报告执行结果
# !...后面就是执行windows命令了。呵呵，去问bill gates什么意思吧。

----------------------------------------

# FTPing from VIM
# 用 VIM 通过 ftp 编辑文件
:cmap ,r  :Nread ftp://209.51.134.122/public_html/index.html
:cmap ,w  :Nwrite ftp://209.51.134.122/public_html/index.html
gvim ftp://209.51.134.122/public_html/index.html
# 译注：cmap是命令(command)模式绑定

----------------------------------------

# appending to registers (use CAPITAL)
# 附加到一个register (用大写的register名字)
"a5yy   #复制5行到a中
10j     #下移10行
"A5yy   #再添加5行到a中

----------------------------------------

[I     : show lines matching word under cursor <cword> (super)
          显示光标处的狭义字可以匹配的行(高级指令)
        # 译注：# 可以全文查找与光标处的狭义字相匹配的字，
        # 这在查找函数原型和实现，或者变量使用的时候很有用

----------------------------------------

# Conventional Shifting/Indenting
# 常规缩进
:'a,'b>>   # 把mark a到mark b之间的内容缩进两次

# visual shifting (builtin-repeat)
# 在visual模式下缩进 (无限可重复)
:vnoremap < <gv #="" 译释：:vnoremap="" 重定义了visual模式下="" <="" 符号的含义="" 把它定义成="" <gv="" 即：先<向外缩进，然后gv重新选择上一次选择了的区域="" 这样在visual模式下就可以实现连续按<而连续缩进了="" :vnoremap=""> >gv
# 同里，内缩

# Block shifting (magic)
# 块缩进
 >i{
 >a{
# also
 >% and <% ----------------------------------------="" #="" redirection="" &="" paste="" register="" *="" 重定向到剪贴板和从剪贴板粘贴="" :redir="" @*="" :="" redirect="" commands="" to="" buffer="" 重定向命令的输出结果（最下方命令行上的结果）="" end="" 结束重定向="">> out.txt            : redirect to a file
                                重定向到一个文件
# Working with Paste buffer
# 操作剪贴板
"*yy                         : yank to paste
                                复制到剪贴板中
"*p                          : insert from paste buffer
                                从剪贴板中粘贴
# yank to paste buffer (ex mode)
# 拷贝到剪贴板 (ex 模式)
:'a,'by*                     : Yank range into paste
                                把标记a到标记b见的内容拷贝到剪贴板
:%y*                         : Yank whole buffer into paste
                                把整个文件拷贝到剪贴板
# filter non-printable characters from the paste buffer
# 从剪贴板上过滤非可打印字符
# useful when pasting from some gui application
# 当从一些 GUI 程序粘贴时会有用处
:nmap <leader>p :let @* = substitute(@*,'[^[:print:]]','','g')<cr>"*p
----------------------------------------
# Re-Formatting text
# 重新格式化文本
gq}                          : Format a paragraph
                                格式化一个段落
ggVGgq                       : Reformat entire file
                                重新格式化整个文件
Vgq                          : current line
                                格式化当前行
# break lines at 70 chars, if possible after a ;
# 在70列的时候换行
:s/.\{,69\};\s*\|.\{,69\}\s\+/&\r/g
----------------------------------------
# Operate command over multiple files
# 对多个文档实施命令
:argdo %s/foo/bar/e          : operate on all files in :args
                                对所有:args列表中的文档执行命令
:bufdo %s/foo/bar/e
:windo %s/foo/bar/e
:argdo exe '%!sort'|w!       : include an external command
                                使用外部命令
:bufdo /foo/
----------------------------------------
# Command line tricks
# 命令行上的技巧
gvim -h                    : help
                              启动帮助
ls | gvim -                : edit a stream!!
                              编辑一个数据流
cat xx | gvim - -c "v/^\d\d\|^[3-9]/d " : filter a stream
gvim -o file1 file2        : open into a split
                              以分割窗口打开两个文件

# execute one command after opening file
# 指出打开之后执行的命令
gvim.exe -c "/main" joe.c  : Open joe.c & jump to "main"

# execute multiple command on a single file
# 对一个文件执行多个命令
vim -c "%s/ABC/DEF/ge | update" file1.c

# execute multiple command on a group of files
# 对一组文件执行多个命令
vim -c "argdo %s/ABC/DEF/ge | update" *.c

# remove blocks of text from a series of files
# 从一组文件中删除文本块
vim -c "argdo /begin/+1,/end/-1g/^/d | update" *.c

# Automate editting of a file (Ex commands in convert.vim)
# 自动编辑文件 (编辑命令序列Ex commands已经包含在convert.vim中了)
vim -s "convert.vim" file.c

#load VIM without .vimrc and plugins (clean VIM)
# 不要加载.vimrc和任何plugins (启动一个干净的VIM)
gvim -u NONE -U NONE -N

# Access paste buffer contents (put in a script/batch file)
# 读取剪贴板内容 (放到脚本或批处理文件中)
gvim -c 'normal ggdG"*p' c:/aaa/xp

# print paste contents to default printer
# 把剪贴板内容打印到默认打印机
gvim -c 's/^/\=@*/|hardcopy!|q!'
----------------------------------------
# GVIM Difference Function (Brilliant)
gvim -d file1 file2        : vimdiff (compare differences)
                              vimdiff (比较不同)
dp                         : "put" difference under cursor to other file
                              把光标处的不同放到另一个文件
do                         : "get" difference under cursor from other file
                              在光标处从另一个文件取得不同
----------------------------------------
# Vim traps
# Vim陷阱
In regular expressions you must backslash + (match 1 or more)
In regular expressions you must backslash | (or)
In regular expressions you must backslash ( (group)
In regular expressions you must backslash { (count)
# 在vim的正则表达式中， + | ( { 前都必须加转义符 \
/fred\+/                   : matches fred/freddy but not free
                              匹配fred或freddy但是不匹配free
/\(fred\)\{2,3}/           : note what you have to break
                              ???
----------------------------------------
# \v or very magic (usually) reduces backslashing
# \v ，或叫做very magic (通常都是这么叫)可以取消转义符
/codes\(\n\|\s\)*where  : normal regexp
                           普通的正则表达式
/\vcodes(\n|\s)*where   : very magic
----------------------------------------
# pulling objects onto command/search line (SUPER)
# 把东西送到命令行/搜索行 (SUPER)
<c-r><c-w> : pull word under the cursor into a command line or search
                    送一个狭义词
<c-r><c-a> : pull WORD under the cursor into a command line or search
                    送一个广义词
<c-r>-                  : pull small register (also insert mode)
                             送一个小型寄存器 (插入模式下也有效)
<c-r>[0-9a-z]           : pull named registers (also insert mode)
                              送一个命名寄存器 (插入模式下也有效)
<c-r>%                  : pull file name (also #) (also insert mode)
                              送文件名过去 (#也行) (插入模式下也有效)
----------------------------------------
# manipulating registers
# 操作寄存器
:let @a=@_              : clear register a
                           清空寄存器a
:let @a=""              : clear register a
                           同上
:let @*=@a              : copy register a to paste buffer
                           拷贝寄存器 a 的内容到剪贴板
map   <f11> "qyy:let @q=@q."zzz"

----------------------------------------

# help for help
# 关于帮助的帮助
:h quickref             : VIM Quick Reference Sheet (ultra)
                           VIM 快速参考手册 (ultra)
:h tips                 : Vim's own Tips Help
                           Vim自己的tips
:h visual<c-d><tab>     : obtain  list of all visual help topics
                                得到一个关于visual关键字的帮助列表
                         : Then use tab to step thru them
                        : 然后用tab键去选择
:h ctrl<c-d>         : list help of all control keys
                           显示所有关于Ctrl的帮助
:helpg uganda           : Help grep
                           显示 grep 帮助
:h :r                   : help for :ex command
                           :ex冒号命令
:h CTRL-R               : normal mode
                           普通模式命令
:h /\r                  : what's \r in a regexp (matches a <cr>)
                           \r在正则表达式中是什么意思呢？
:h \\zs                 : double up backslash to find \zs in help
:h i_CTRL-R             : help for say <c-r> in insert mode
                           insert模式下的Ctrl-R
:h c_CTRL-R             : help for say <c-r> in command mode
                           命令行(command-line)模式下的Ctrl-R
:h v_CTRL-V             : visual mode
                           visual模式下的Ctrl-V
:h tutor                : VIM Tutor
                           VIM 指南
<c-[>, <c-t>      : Move back & Forth in HELP History
                           在帮助历史中，向前/后移动
gvim -h                 : VIM Command Line Help
                           关于 VIM 命令的帮助
----------------------------------------
# where was an option set
# 选项设置在哪里？
:scriptnames            : list all plugins, _vimrcs loaded (super)
                           列出所有加载的 plugins, _vimrcs
:verbose set history?   : reveals value of history and where set
                           显示history的值并指出设置文件的位置
:function               : list functions
                           列出所有函数
:func SearchCompl       : List particular function
                          列出指定的函数

----------------------------------------

# making your own VIM help
# 制作你自己的VIM帮助
:helptags /vim/vim63/doc  : rebuild all *.txt help files in /doc
                             重建 /doc 中所有的 *.txt 帮助文件
:help add-local-help

----------------------------------------
# running file thru an external program (eg php)
# 用外部程序来运行程序 (例如 php)
map   <f9>   :w<cr>:!c:/php/php.exe %<cr>
map   <f2>   :w<cr>:!perl -c %<cr>
----------------------------------------
# capturing output of current script in a separate buffer
# 在另一个buffer中，捕捉当前脚本的输出
:new | r!perl #                   : opens new buffer,read other buffer
                                     新建一个buffer，从另一个buffer中读入结果
:new! x.out | r!perl #            : same with named file
                                    同上，并指定一个新文件名

----------------------------------------

# Inserting DOS Carriage Returns
# 插入DOS换行符
:%s/nubian/<c-v><c-m>&/g          :  that's what you type
:%s/nubian/<c-q><c-m>&/g          :  for Win32
                                            对于Win32应该这样
dn_...@yahoo.ca
:%s/nubian/^M&/g                  :  what you'll see where ^M is ONE character
                                      你看到的^M是一个字符
:%s/nubian/\r&/g                  :  better
                                      更好的形式

----------------------------------------

# automatically delete trailing Dos-returns,whitespace
# 自动删除行尾 Dos回车符和空格
autocmd BufRead * silent! %s/[\r \t]\+$//
autocmd BufEnter *.php :%s/[ \t\r]\+$//e
----------------------------------------
# perform an action on a particular file or file type
# 对指定文件或文件类型执行某个动作
autocmd VimEnter c:/intranet/note011.txt normal! ggVGg?
autocmd FileType *.pl exec('set fileformats=unix')
----------------------------------------
# Retrieving last command line command for copy & pasting into text
# 把最后一个命令贴到当前位置
i<c-r>:
# Retrieving last Search Command for copy & pasting into text
# 把最后一个搜索指令贴到当前位置
i<c-r>/
# 译释：i是进入insert模式，
# Ctrl-r是开启插入模式下register的引用
# :和/分别引用了两个register的内容
----------------------------------------
# more completions
# 更多的完成功能
<c-x><c-f>     :insert name of a file in current directory
                      插入当前目录下的一个文件名到当前位置
# 在insert模式下使用
# 然后用 Ctrl-P/Ctrl-N 翻页

----------------------------------------

# Substituting a Visual area
# 替换一个visual区域
# select visual area as usual (:h visual) then type :s/Emacs/Vim/ etc
# 选择一个区域，然后输入 :s/Emacs/Vim/ 等等，vim会自动进入:模式
:'<,'>s/Emacs/Vim/g               : REMEMBER you dont type the '<.'>
                                        前面的'<,'>是vim自动添加的
gv                                : Re-select the previous visual area (ULTRA)
                                     重新选择前一个可视区域 (ULTRA)
----------------------------------------
# inserting line number into file
# 在文件中插入行号
:g/^/exec "s/^/".strpart(line(".")."    ", 0, 4)
:%s/^/\=strpart(line(".")."     ", 0, 5)
:%s/^/\=line('.'). ' '
----------------------------------------
#numbering lines VIM way
# 用VIM的方式来编号行
:set number                       : show line numbers
                                     显示行号
:map <f12> :set number!<cr>       : Show linenumbers flip-flop
:%s/^/\=strpart(line('.')."        ",0,&ts)

#numbering lines (need Perl on PC) starting from arbitrary number
#从任意行开始编号(需要perl)
:'a,'b!perl -pne 'BEGIN{$a=223} substr($_,2,0)=$a++'

# Produce a list of numbers
# 产生数字列表
#Type in number on line say 223 in an empty file
qqmnYP`n^Aq                       : in recording q repeat with @q
# increment existing numbers to end of file (type <c-a> as 5 characters)
# 递增已存在数字到文件末
:.,$g/^\d/exe "normal! \<c-a>"
# advanced incrementing
# 高级递增，参见：
http://vim.sourceforge.net/tip_view.php?tip_id=150
----------------------------------------
# advanced incrementing (really useful)
# 高级递增 (真的很有用)
" put following in _vimrc
" 把下面几句放到 _vimrc #vimrc脚本用 " 做行注释符
let g:I=0
function! INC(increment)
let g:I =g:I + a:increment
return g:I
endfunction
" eg create list starting from 223 incrementing by 5 between markers a,b
" 例如从mark a 到mark b 递增，从223开始，步长为5
:let I=223
:'a,'bs/^/\=INC(5)/
" create a map for INC
cab viminc :let I=223 \| 'a,'bs/$/\=INC(5)/
----------------------------------------
# editing/moving within current insert (Really useful)
# 在当前插入模式下编辑/移动 (真得很有用)
<c-u>                             : delete all entered
                                        删除全部
<c-w>                             : delete last word
                                        删除最后一个单词
<home><end>                       : beginning/end of line
                                           移动到行首/行尾
<c-leftarrow><c-rightarrow>       : jump one word backwards/forwards
                                           向前/后移动一个单词
<c-x><c-e>,<c-x><c-y>             : scroll while staying put in insert
----------------------------------------
#encryption (use with care: DON'T FORGET your KEY)
# 加密(小心使用，不要忘了密码)
:X                                : you will be prompted for a key
                                     vim会提示你输入密码
:h :X
----------------------------------------
# modeline (make a file readonly etc) must be in first/last 5 lines
# 模式行 (使文件只读等)，必须在前/后 5行内
// vim:noai:ts=2:sw=4:readonly:
# vim:ft=html:                    : says use HTML Syntax highlighting
                                     使用 HTML 语法高亮
:h modeline
----------------------------------------
# Creating your own GUI Toolbar entry
# 建立你自己的菜单项
amenu  Modeline.Insert\ a\ VIM\ modeline <esc><esc>ggOvim:ff=unix ts=4 
ss=4<cr>vim60:fdm=marker<esc>gg

----------------------------------------

# A function to save word under cursor to a file
# 一个保存当前光标下的狭义字到一个文件的函数
function! SaveWord()
    normal yiw
    exe ':!echo '.@0.' >> word.txt'
endfunction
map ,p :call SaveWord()

----------------------------------------

# function to delete duplicate lines
# 删除重复行的函数
function! Del()
  if getline(".") == getline(line(".") - 1)
    norm dd
  endif
endfunction

:g/^/ call Del()  #使用该函数的一个例子

----------------------------------------

# Digraphs (non alpha-numerics)
# 双字节编码 (non alpha-numerics)
:digraphs                         : display table
                                     显示编码表
:h dig                            : help
                                     帮助
i<c-k>e'                          : enters �
                                        输入 é
i<c-v>233                         : enters � (Unix)
                                       输入 é (Unix)
i<c-q>233                         : enters � (Win32)
                                        输入 é (Win32)
ga                                : View hex value of any character
                                     查看字符的hex值

# Deleting non-ascii characters (some invisible)
# 删除非 ascii 字符
:%s/[<c-v>128-<c-v>255]//gi       : where you have to type the Control-V
:%s/[€-�]//gi                     : Should see a black square & a dotted y
:%s/[<c-v>128-<c-v>255<c-v>01-<c-v>31]//gi : All pesky non-asciis
:exec "norm /[\x00-\x1f\x80-\xff]/"        : same thing
#Pull a non-ascii character onto search bar
yl/<c-r>"                         :
----------------------------------------
# All file completions grouped (for example main_c.c)
# 文件名自动完成 (例如 main_c.c)
:e main_<tab>                     : tab completes
                                        tab 键完成
gf                                : open file under cursor  (normal)
                                     打开光标处广义字命名的文件 (normal模式)
main_<c-x><c-f>                   : include NAME of file in text (insert mode)
                                           文件名自动完成(insert模式)
----------------------------------------
# Complex Vim
# Vim复杂使用
# swap two words
# 交换两个单词
:%s/\<\(on\|off\)\>/\=strpart("offon", 3 * ("off" == submatch(0)), 3)/g
# swap two words
# 交换两个单词
:vnoremap <c-x> <esc>`.``gvP``P
----------------------------------------
# Convert Text File to HTML
# 把text文件转换成html文件(oh,ft)
:runtime! syntax/2html.vim        : convert txt to html
                                    转换 txt 成 html
:h 2html
----------------------------------------
# VIM has internal grep
# VIM 有一个内部自带的 grep 命令
:grep some_keyword *.c            : get list of all c-files containing keyword
                                     得到一个包含some_keyword的c文件名列表
:cn                               : go to next occurrence
                                     去下一个出现的位置
----------------------------------------
# Force Syntax coloring for a file that has no extension .pl
# 强制无扩展名的文件的语法着色方式
:set syntax=perl
# Remove syntax coloring (useful for all sorts of reasons)
# 取消语法着色 (很有用)
:set syntax off
# change coloring scheme (any file in ~vim/vim??/colors)
# 改变色彩主题 (在~vim/vim??/colors中的任何文件)
:colorscheme blue
# Force HTML Syntax highlighting by using a modeline
# 通过使用模式行强迫使用 HTML 语法高亮
# vim:ft=html:
----------------------------------------
:set noma (non modifiable)        : Prevents modifications
                                     防止修改
:set ro (Read Only)               : Protect a file from unintentional writes
                                     只读保护
----------------------------------------
# Sessions (Open a set of files)
# 对话 (打开一堆文件)
gvim file1.c file2.c lib/lib.h lib/lib2.h : load files for "session"
                                            在"对话"中加载这些文件
:mksession                        : Make a Session file (default Session.vim)
                                     生成一个Session文件 (默认是Session.vim)
:q
gvim -S Session.vim               : Reload all files
                                     重新加载所有文件
----------------------------------------
# tags (jumping to subroutines/functions)
# 标记(tags) (跳转到子程序/函数)
taglist.vim                       : popular plugin
                                     很流行的插件
:Tlist                            : display Tags (list of functions)
                                     显示标记 (函数列表)
<c-]>                             : jump to function under cursor
                                        跳转到光标处的函数
----------------------------------------
# columnise a csv file for display only as may crop wide columns
:let width = 20
:let fill=' ' | while strlen(fill) < width | let fill=fill.fill | endwhile
:%s/\([^;]*\);\=/\=strpart(submatch(1).fill, 0, width)/ge
:%s/\s\+$//ge
# Highlight a particular csv column (put in .vimrc)
function! CSVH(x)
     execute 'match Keyword /^\([^,]*,\)\{'.a:x.'}\zs[^,]*/'
     execute 'normal ^'.a:x.'f,'
endfunction
command! -nargs=1 Csv :call CSVH(<args>)
# call with
:Csv 5                             : highlight fith column
----------------------------------------
# folding : hide sections to allow easier comparisons
# 折叠：隐藏某些片断，是查看更容易
zf}                               : fold paragraph using motion
                                     使用动作命令折叠一个段落
v}zf                              : fold paragraph using visual
                                     使用可视模式折叠一个段落
zf'a                              : fold to mark
                                     折叠到一个标记上
zo                                : open fold
                                     打开折叠
zc                                : re-close fold
                                     重新关闭折叠
----------------------------------------
# displaying "invisible characters"
# 显示"不可见字符"
:set list
:h listchars
----------------------------------------
# How to paste "normal commands" w/o entering insert mode
# 如何在不进入插入模式的情况下粘贴"普通模式的命令"
:norm qqy$jq
----------------------------------------
# manipulating file names
# 处理文件名
:h filename-modifiers             : help
                                     帮助
:w %                              : write to current file name
                                     写入当前文件
:w %:r.cfm                        : change file extention to .cfm
                                     改变文件扩展名为 .cfm
:!echo %:p                        : full path & file name
                                     显示完整路径和文件名
:!echo %:p:h                      : full path only
                                     只显示完整路径
<c-r>%                            : insert filename (insert mode)
                                        插入文件名 (插入模式)
"%p                               : insert filename (normal mode)
                                    插入文件名 (普通模式)
/<c-r>%                           : Search for file name in text
                                        在文本中查找文件名
----------------------------------------
# delete without destroying default buffer contents
# 删除，但不破坏 buffer 内容
"_d                               : what you've ALWAYS wanted
                                     你一直想要的东西
"_dw                              : eg delete word (use blackhole)
                                     例如：删除一个单词 (使用黑洞???)
----------------------------------------
# pull full path name into paste buffer for attachment to email etc
# 送完整的路径名到剪贴板，用于邮件附件等
nnoremap <f2> :let @*=expand("%:p")<cr> :unix
nnoremap <f2> :let @*=substitute(expand("%:p"), "/", "\\", "g")<cr> :win32
----------------------------------------
# Simple Shell script to rename files w/o leaving vim
# 不用离开 Vim 就能修改文件名的简单 shell 脚本
$ vim
:r! ls *.c
:%s/\(.*\).c/mv & \1.bla
:w !sh
:q!
----------------------------------------
# count words in a text file
# 在一个文本里计算单词数
g<c-g>
----------------------------------------
# example of setting your own highlighting
# 你自己设置高亮显示的例子
:syn match DoubleSpace "  "
:hi def DoubleSpace guibg=#e0e0e0
----------------------------------------
# Programming keys depending on file type
# 根据文件类型映射快捷键
:autocmd bufenter *.tex map <f1> :!latex %<cr>
:autocmd bufenter *.tex map <f2> :!xdvi -hush %<.dvi&<cr>
----------------------------------------
# reading Ms-Word documents, requires antiword
# 读取 MS-Word 文档，需要 antiword
:autocmd BufReadPre *.doc set ro
:autocmd BufReadPre *.doc set hlsearch!
:autocmd BufReadPost *.doc %!antiword "%"
----------------------------------------
# Just Another Vim Hacker JAVH
vim -c ":%s%s*%Cyrnfr)fcbafbe[Oenz(Zbbyranne%|:%s)[[()])-)Ig|norm Vg?"
# 译释：呵呵，谁来解释一下吧！
# 其实不过是在启动vim的时候执行了一个命令
# 先写入了 Just Another Vim Hacker 的rot13编码
# 然后再解码
----------------------------------------
__END__
</.dvi&<cr></f2></cr></f1></c-g></cr></f2></cr></f2></c-r></c-r></args></c-]></esc></c-x></\(on\|off\)\></c-f></c-x></tab></c-r></c-v></c-v></c-v></c-v></c-v></c-v></c-q></c-v></c-k></esc></cr></esc></esc></c-y></c-x></c-e></c-x></c-rightarrow></c-leftarrow></end></home></c-w></c-u></c-a></c-a></cr></f12></,'></.'></,'></c-f></c-x></c-r></c-r></c-m></c-q></c-m></c-v></cr></cr></f2></cr></cr></f9></c-t></c-[></c-r></c-r></cr></c-d></tab></c-d></f11></c-r></c-r></c-r></c-a></c-r></c-w></c-r></cr></leader></%></gv></cword></cr></cword></cr></cr></cr></c-q></c-v></c-q></c-v></c-v></c-v></,'></,'></ctrl-r></c-w></c-w></c-k></c-w></c-w></c-j></cr></.bak></cr></cr></cword></c-r></leader></backspace></bar></leader></esc></cr></cr></f12></cr></cr></f11></f8></f7></c-f></c-i></c-o></c-r></c-x></c-a></cr></\(.\)\(\k*\)\></esc></esc></c-d></cword></cword></c-a></c-r></cword></cword></c-w></c-r></c-l></c-x></c-p></cword></cword></c-a></input\|<form></pattern></pattern></=></c-r></c-u></leader></cr></cword></c-r></=\d\+></cr></bar></bar></bar></\(input\<bar></bar></\(input\|select\|textarea\|></c-r></[zy]\?tbl_[a-z_]\+\></cr></c-r></bar></cr></cr></c-r></silent></cr></c-r></\d\{4}\></\d\d\d\d\></fred\></pre>

      
    </div>
    <footer class="article-footer">
	  
	  <!-- 百度分享 Start -->
	  <div class="bdsharebuttonbox"><a href="#" class="bds_more" data-cmd="more"></a><a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a><a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a><a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博"></a><a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网"></a><a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a></div>
	  <!-- 百度分享 End -->
	  
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Vim/">Vim</a></li></ul>

	  
<span>
Updated:<time datetime="2014-12-24T07:43:41.000Z" itemprop="dateModified">2014-12-24</time>
</span>


    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2014/02/03/linux-system-info/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Linux系统信息
        
      </div>
    </a>
  
  
    <a href="/2013/12/02/vim-is-the-god-of-all-editors/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">编辑器之神Vim</div>
    </a>
  
</nav>

  
</article>



<!-- 多说评论框 start -->

<section id="comments">
  <div class="ds-thread"  data-thread-key="/2014/01/26/best-vim-tips/" data-title="Best of Vim Tips 中文版" data-url="http://howiefh.github.io/2014/01/26/best-vim-tips/" id="ds_thread">
    <noscript>Please enable JavaScript to view the <a href="//duoshuo.com/?ref_noscript">comments powered by duoshuo.</a></noscript>
  </div>
</section>

<!-- 多说评论框 end -->
</section>
        
          
  <div id="toc" class="toc-aside">
  <h2 class="toc-title">Contents</h2>
    
        
    
  </div>

<aside id="sidebar">

  
    
<div class="widget-wrap">
  <h3 class="widget-title">ABOUT ME</h3>
  <ul class="widget about-me">
    
    <li><img class="author" title="About me" src="http://fh-1.qiniudn.com/okal-eltocat.jpg" /></li>
    
    
    <li>Hi,I'm FengHao.</li>
    
    <li>I'll share something interesting and my learning experience with you at this blog.</li>
    
    <li>前博客:<a href="http://hi.baidu.com/idea_star" target="_BLANK">百度空间</a></li>
    
  </ul>
</div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Android/">Android</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/C/">C</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Database/">Database</a><span class="category-list-count">13</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/Database/MongoDB/">MongoDB</a><span class="category-list-count">10</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Database/MySQL/">MySQL</a><span class="category-list-count">2</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/Eclipse/">Eclipse</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/FTP/">FTP</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Git/">Git</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Hexo/">Hexo</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Java/">Java</a><span class="category-list-count">20</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/Java/FreeMarker/">FreeMarker</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Java/Shiro/">Shiro</a><span class="category-list-count">2</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaEE/">JavaEE</a><span class="category-list-count">4</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/JavaEE/Hibernate/">Hibernate</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaEE/JSP/">JSP</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaEE/Spring/">Spring</a><span class="category-list-count">2</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaScript/">JavaScript</a><span class="category-list-count">5</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/JavaScript/jQuery/">jQuery</a><span class="category-list-count">1</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/Linux/">Linux</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/PHP/">PHP</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Suse/">Suse</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Ubuntu/">Ubuntu</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Vim/">Vim</a><span class="category-list-count">8</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/编程/">编程</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/软件/">软件</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Android/" style="font-size: 14.75px; color: #65bfa7">Android</a> <a href="/tags/C/" style="font-size: 13.88px; color: #71c1c2">C</a> <a href="/tags/CAS/" style="font-size: 13px; color: #7dc3de">CAS</a> <a href="/tags/Chrome/" style="font-size: 13px; color: #7dc3de">Chrome</a> <a href="/tags/Clean-Code/" style="font-size: 13.88px; color: #71c1c2">Clean Code</a> <a href="/tags/Database/" style="font-size: 13px; color: #7dc3de">Database</a> <a href="/tags/Eclipse/" style="font-size: 13px; color: #7dc3de">Eclipse</a> <a href="/tags/FTP/" style="font-size: 13.88px; color: #71c1c2">FTP</a> <a href="/tags/FreeMarker/" style="font-size: 14.75px; color: #65bfa7">FreeMarker</a> <a href="/tags/Gcc/" style="font-size: 13px; color: #7dc3de">Gcc</a> <a href="/tags/Git/" style="font-size: 14.75px; color: #65bfa7">Git</a> <a href="/tags/Github-Pages/" style="font-size: 13px; color: #7dc3de">Github Pages</a> <a href="/tags/Hexo/" style="font-size: 14.75px; color: #65bfa7">Hexo</a> <a href="/tags/Hibernate/" style="font-size: 13px; color: #7dc3de">Hibernate</a> <a href="/tags/JSP/" style="font-size: 13px; color: #7dc3de">JSP</a> <a href="/tags/JVM/" style="font-size: 14.75px; color: #65bfa7">JVM</a> <a href="/tags/Java/" style="font-size: 14.75px; color: #65bfa7">Java</a> <a href="/tags/JavaMail/" style="font-size: 13px; color: #7dc3de">JavaMail</a> <a href="/tags/JavaScript/" style="font-size: 16.5px; color: #4dbc6f">JavaScript</a> <a href="/tags/Linux/" style="font-size: 13.88px; color: #71c1c2">Linux</a> <a href="/tags/Log/" style="font-size: 13px; color: #7dc3de">Log</a> <a href="/tags/Markdown/" style="font-size: 13.88px; color: #71c1c2">Markdown</a> <a href="/tags/MongoDB/" style="font-size: 20px; color: #1db400">MongoDB</a> <a href="/tags/MySQL/" style="font-size: 13.88px; color: #71c1c2">MySQL</a> <a href="/tags/PHP/" style="font-size: 16.5px; color: #4dbc6f">PHP</a> <a href="/tags/Rhythmbox/" style="font-size: 13px; color: #7dc3de">Rhythmbox</a> <a href="/tags/SSO/" style="font-size: 13px; color: #7dc3de">SSO</a> <a href="/tags/Servlet/" style="font-size: 13px; color: #7dc3de">Servlet</a> <a href="/tags/Shiro/" style="font-size: 13.88px; color: #71c1c2">Shiro</a> <a href="/tags/Spring/" style="font-size: 13.88px; color: #71c1c2">Spring</a> <a href="/tags/Suse/" style="font-size: 13px; color: #7dc3de">Suse</a> <a href="/tags/Thinking-in-Java/" style="font-size: 19.13px; color: #29b61c">Thinking in Java</a> <a href="/tags/Ubuntu/" style="font-size: 17.38px; color: #41ba53">Ubuntu</a> <a href="/tags/Vim/" style="font-size: 18.25px; color: #35b838">Vim</a> <a href="/tags/VirtualBox/" style="font-size: 13px; color: #7dc3de">VirtualBox</a> <a href="/tags/Vsftpd/" style="font-size: 13px; color: #7dc3de">Vsftpd</a> <a href="/tags/jQuery/" style="font-size: 13px; color: #7dc3de">jQuery</a> <a href="/tags/pam-mysql/" style="font-size: 13px; color: #7dc3de">pam_mysql</a> <a href="/tags/小米/" style="font-size: 13px; color: #7dc3de">小米</a> <a href="/tags/软件/" style="font-size: 15.63px; color: #59bd8b">软件</a>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/09/">September 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/08/">August 2015</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/07/">July 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/05/">May 2015</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/04/">April 2015</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/03/">March 2015</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/02/">February 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/12/">December 2014</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/11/">November 2014</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/10/">October 2014</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/09/">September 2014</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/08/">August 2014</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/07/">July 2014</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/06/">June 2014</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/05/">May 2014</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/04/">April 2014</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/03/">March 2014</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/02/">February 2014</a><span class="archive-list-count">11</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/01/">January 2014</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/12/">December 2013</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/11/">November 2013</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/08/">August 2013</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/07/">July 2013</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/06/">June 2013</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/05/">May 2013</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/04/">April 2013</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2012/03/">March 2012</a><span class="archive-list-count">1</span></li></ul>
    </div>
  </div>


  
    <div class="widget-wrap">
  <h3 class="widget-title">Calendar</h3>
  <div class="widget">
    <div id="g-calendar" class="g-calendar">
        <span class="g-calendar-prev"></span>
		 
        <span class="g-calendar-back"></span>
        <span class="g-calendar-now"></span>
		 
        <span class="g-calendar-next"></span>
        <div class="g-calendar-hd"></div>
        <div class="g-calendar-tit"></div>
        <div class="g-calendar-bd"></div>
    </div>
  </div>
</div>
<script type="text/javascript">
function LGY_calendar(wrapId, options){
    this.oWrap = this.getId(wrapId);
    this.oHead = this.getByClassName('g-calendar-hd',this.oWrap)[0];
    this.oBody = this.getByClassName('g-calendar-bd',this.oWrap)[0];
    this.oTit = this.getByClassName('g-calendar-tit',this.oWrap)[0];
    this.oPrev = this.getByClassName('g-calendar-prev',this.oWrap)[0];
    this.oNext = this.getByClassName('g-calendar-next',this.oWrap)[0];
    this.oNow = this.getByClassName('g-calendar-now',this.oWrap)[0];
    this.oBack = this.getByClassName('g-calendar-back',this.oWrap)[0];
    this.init();
}
LGY_calendar.prototype = {
    ///////////获取ID元素
    getId:function(id){
        return document.getElementById(id);
    },
    ////////获取css类名元素
    getByClassName:function(className,parent){
        var elem = [],
            node = parent != undefined&&parent.nodeType==1?parent.getElementsByTagName('*'):document.getElementsByTagName('*'),
            p = new RegExp("(^|\\s)"+className+"(\\s|$)");
        for(var n=0,i=node.length;n<i;n++){
            if(p.test(node[n].className)){
                elem.push(node[n]);
            }
        }
        return elem;
    },
    //填充日历
    fillDate:function(year,month){
        //本月份第一天是星期几-为显示上个月的天数做铺垫
        var first_day = new Date(year,month,1).getDay(),
        //如果刚好是星期天，则空出一行（显示上个月的天数）
            first_day = first_day == 0?first_day=7:first_day;
        //本月份最后一天是几号
        var final_date = new Date(year,month+1,0).getDate(),
        //上个月的最后一天是几号
            last_date = new Date(year,month,0).getDate(),
        //剩余的格子数--即排在末尾的格子数
            surplus = 42 - first_day - final_date;
        //设置年的链接
        var yearHead = "<a href='/" + "archives/" + year + "/'>" + year + " "+ "</a>"; 
        //设置年的链接
        var monthHead = "";
        var month1 = month + 1;
        if (month1 < 10) {
            monthHead = "<a href='/" + "archives/" + year + "/" + "0" + month1 + "/'>" + " " + month1 + " " + "</a>";
        } else {
            monthHead = "<a href='/" + "archives/" + year + "/" + month1 + "/'>" + " " + month1 + " " + "</a>";
        }
        //设置表头的日历
        this.oHead.innerHTML = yearHead+'年'+monthHead+'月';
        //填充日历执行
        var html = '';
        //上个月的显示天数
        for(var i=0;i<first_day;i++){
            html+='<span class="g-calendar-grey">'+(last_date-(first_day-1)+i)+'</span>';
        }
        //本月的显示天数
        var postdate = new Date("Sun Jan 26 2014 17:48:52 GMT+0800"); 
        if (true && postdate.getFullYear() == year && postdate.getMonth() == month) { 
            html += '<span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span><span>8</span><span>9</span><span>10</span><span>11</span><span>12</span><span>13</span><span>14</span><span>15</span><span>16</span><span>17</span><span>18</span><span>19</span><span>20</span><span>21</span><span>22</span><span>23</span><span>24</span><span>25</span><span><a href="/2014/01/26/best-vim-tips/" title="Best of Vim Tips 中文版">26</a></span><span>27</span><span>28</span><span>29</span><span>30</span><span>31</span>';
        } else {
            for(var j=0;j<final_date;j++){        
                html+='<span id="d'+(j+1)+'">'+(j+1)+'</span>';
            }
        }
        //下个月的显示天数
        for(var k=0;k<surplus;k++){
            html+='<span class="g-calendar-grey">'+(k+1)+'</span>';
        }
        //fill
        this.oBody.innerHTML = html;
        // 当前状态
        if(year==this.c_year&&this.c_month==month){
            this.oBody.getElementsByTagName('span')[first_day+this.date-1].className='g-calendar-on';
        }

        // 对所有文章遍历,然后将有文章的日期加上链接,如果文章太多的话,生成页面会很大,去掉了
        
    },
    // next切换
    next:function(){
        var _that = this;
        this.oNext.onclick = function(){
            _that.month++;
            if(_that.month>11){
                _that.month = 0;
                _that.year++;
            }
            // 填充日历
            _that.fillDate(_that.year,_that.month);
        };
    },
    // back 切换
    back:function(){
        var _that = this;
        if(this.oBack != undefined) {
            this.oBack.onclick = function(){
                var postdate = new Date("Sun Jan 26 2014 17:48:52 GMT+0800"); 
                _that.year = postdate.getFullYear();
                _that.month = postdate.getMonth();
                // 填充日历
                _that.fillDate(_that.year,_that.month);
            };
        }
    },
    // now切换
    now:function(){
        var _that = this;
        if(this.oNow != undefined ) {
            this.oNow.onclick = function(){
                var nowDate = new Date(); 
                _that.year = nowDate.getFullYear();
                _that.month = nowDate.getMonth();
                // 填充日历
                _that.fillDate(_that.year,_that.month);
            };
        }
    },
    // prev切换
    prev:function(){
        var _that = this;
        this.oPrev.onclick = function(){
            _that.month--;
            if(_that.month<0){
                _that.month = 11;
                _that.year--;
            }
            // 填充日历
            _that.fillDate(_that.year,_that.month);
        };
    },
    init:function(){
        this.oTit.innerHTML = '<span>日</span><span>一</span><span>二</span><span>三</span><span>四</span><span>五</span><span>六</span>';
        // 获取今天的日历时间
        var now = new Date();
        this.c_year = this.year = now.getFullYear();
        this.c_month = this.month = now.getMonth();
        this.date = now.getDate();
        // 初始化--填充日历
        this.fillDate(this.year,this.month);
        //next切换
        this.next();
        //prev切换
        this.prev();
        //back 切换
        this.back();
        //now 切换
        this.now();
    }
}
new LGY_calendar('g-calendar');
</script>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2015/09/01/javascript-summary/">JavaScript 总结</a>
          </li>
        
          <li>
            <a href="/2015/08/28/javascript-oop-function-expression-and-async/">JavaScript 面向对象程序设计、函数表达式和异步编程</a>
          </li>
        
          <li>
            <a href="/2015/08/28/javascript-reference-type/">JavaScript 引用类型</a>
          </li>
        
          <li>
            <a href="/2015/08/28/javascript-grammar/">JavaScript 基本语法</a>
          </li>
        
          <li>
            <a href="/2015/08/10/java-web/">Java Web 笔记</a>
          </li>
        
      </ul>
    </div>
  </div>


  
    
<div class="widget-wrap">
  <h3 class="widget-title">Recent Comments</h3>
  <ul class="widget ds-recent-comments" data-num-items="5" data-show-avatars="0" data-show-title="1" data-show-time="1"></ul>
</div>
<!-- 需要多说的公用代码 -->


  

</aside>

        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2015 howiefh<br>
      Powered by <a href="http://zespia.tw/hexo/" target="_blank">Hexo</a> and Theme by <a href="https://github.com/howiefh/hexo-theme-landscape-f" target="_blank" title="Landscape-F">Landscape-F</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<!-- 多说公共JS代码 start (一个网页只需插入一次) -->

<script type="text/javascript">
  var duoshuoQuery = {short_name:"howiefh"};
  (function() {
	var ds = document.createElement('script');
	ds.type = 'text/javascript';ds.async = true;
	ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
	ds.charset = 'UTF-8';
	(document.getElementsByTagName('head')[0] 
		|| document.getElementsByTagName('body')[0]).appendChild(ds);
  })();
</script> 

<!-- 多说公共JS代码 end -->

<!-- 百度分享 start -->

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":["mshare","douban","bdysc","sqq","qq","hi","baidu","huaban","youdao","sdo","mail","xg","diandian","fx","copy","print"],"bdPic":"","bdStyle":"1","bdSize":"16"},"share":{},"image":{"viewList":["qzone","tsina","tqq","renren","weixin"],"viewText":"分享到：","viewSize":"16"}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>

<!-- 百度分享 end -->

<!--
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="/js/jquery.min.js"></script>
-->
<script src="/js/jquery.min.js" type="text/javascript"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<div class="bottom-btn">

	<a class="icon-gotop" href="javascript:void(0)" title="返回顶部"></a>
	<script src="/js/gotop.js" type="text/javascript"></script>
	<!--
	<script src="/js/gotop.js"></script>
	-->


	<a class="icon-toc-toggle" href="javascript:void(0)" title="文章目录"></a>
	<!--
	<script src="/js/toc_aside_toggle.js"></script>
	-->

</div>
<script src="/js/toc_aside_toggle.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

  </div>
</body>
</html>
